import {Component, Input, OnInit} from '@angular/core';
import {EmployeeListService} from '../../../services/employee-list.service';
import {NativeService} from '../../../services/native.service';
import {Router} from '@angular/router';
import {NbDialogRef} from '@nebular/theme';
import {EmployeeList} from '../../../model/employee-list';

@Component({
  selector: 'ngx-modify-popup',
  templateUrl: './modify-popup.component.html',
  styleUrls: ['./modify-popup.component.scss'],
})
export class ModifyPopupComponent implements OnInit {
  @Input() title: string;
  @Input() name: string;
  @Input() employeeList: EmployeeList;
  state: string;
  content: string;
  constructor(private employeeListService: EmployeeListService, private nativeService: NativeService,
              private router: Router, protected ref: NbDialogRef<ModifyPopupComponent>) { }

  async ngOnInit() {
    console.log(this.employeeList);
  }
  // 确认修改状态
  async modifyState() {
    console.log(this.name, this.state);
    // if (this.userIdList === '') {
    //   this.userIdList = this.id;
    // }
    // console.log(this.userIdList);
    const data = await this.employeeListService.modifyState({name: this.name, state: this.state});
    console.log(data);
    if (data) {
      this.nativeService.showSuccess('当前状态修改成功');
      await this.router.navigateByUrl('/home/employee-list');
    }
    this.ref.close();
  }
  // 取消修改
  cancel() {
    this.ref.close();
  }
}
